//
//  PersonInfoDetailViewController.m
//  MobileOffice
//
//  Created by jjkj on 16/12/7.
//  Copyright © 2016年 liaoningjujin. All rights reserved.
//

#import "PersonInfoDetailViewController.h"
#import "StatisticsTableViewCell.h"
#import "PersonSelectViewController.h"
#import "PersonInfoDetailModel.h"
#import "PersonInfoTableViewCell.h"
#import "PersonInfoHeadTableViewCell.h"
#import "SignInHistoryViewController.h"
#import "AddressSearchModel.h"
#import "CenterLabelTableViewCell.h"
#import "StatisticsListViewController.h"
#import "PersonDetailInfoViewController.h"
#import "PersonSelectViewController.h"

#define getPersonalInformationInfo @"getPersonalInformationInfo"//个人信息汇总查询
#define getDepartEmpName @"getDepartEmpName"//模糊查询条件

#define TEXTMESSAGE @"请输入部门名称或员工姓名"//搜索提示语
@interface PersonInfoDetailViewController ()<UITextFieldDelegate,UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate>
{
    UITableView *_tableView;//列表
    NSMutableArray *_dataArr;
    UITableView *_searchTableView;//搜索结果列表
    AddressSearchModel *_searchListModel;//搜索结果列表model
    UIView *_searchBackView;//搜索view
}
@property (nonatomic,strong)UIView *tableBackView;
@property (nonatomic,strong)UITextField *searchTextField;
@property (nonatomic,strong)PersonInfoDetailModel *infoModel;
@property (nonatomic,strong)NSArray *dateArr;//时间数组
@property (nonatomic,strong)UITableView *infoTableView;//详情tableView
@end

@implementation PersonInfoDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setLeftBackNavigation];
    [self setNavigationTitle:@"个人汇总查询"];
    [self creatView];
    [self creatInfoTableView];
    //默认为本月
    if (self.beginStr==nil||self.endStr==nil) {
        self.beginStr=[LZXHelper getFirstDayInMonth];
        self.endStr=[LZXHelper getLastDayInMonth];
    }
    [self getPersonalInformationInfoRequest];
    // Do any additional setup after loading the view.
}

- (void)creatView{
    self.dateArr=@[@"本月",@"上月",@"本季度",@"上季度",@"上半年",@"下半年"];
    //searchView背景
    UIView *searchView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, self.empIds?80:40)];
    searchView.tag=199;
    [self.view addSubview:searchView];
    
    //设置检索按钮
    NSArray *titleArr=nil;
    
    if (self.empIds) {
        titleArr=@[@"筛选",@"本月"];
        
        _searchTextField=[[UITextField alloc]initWithFrame:CGRectMake(10, 5, IPHONE_WIDTH-20, 30)];        //_spendTextField.color=COLOR_BACKGROUND_GRAY;
        _searchTextField.textAlignment=NSTextAlignmentLeft;
        _searchTextField.delegate=self;
        _searchTextField.font=FONT_14;
        _searchTextField.placeholder=TEXTMESSAGE;
        _searchTextField.backgroundColor=COLOR_BACKGROUND_GRAY;
        //_searchTextField.keyboardType=UIKeyboardTypeNumberPad;
        [searchView addSubview:_searchTextField];
        
        //放大镜
        UIButton *searchBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        searchBtn.frame=CGRectMake(IPHONE_WIDTH-20-20, 0, 15, 40);
        searchBtn.tag=160;
        [searchBtn setImage:[UIImage imageNamed:@"icon_3_n@2x"] forState:UIControlStateNormal];
        [searchBtn addTarget:self action:@selector(searchClick) forControlEvents:UIControlEventTouchUpInside];
        [searchView addSubview:searchBtn];
        //分割线
        UILabel *line1=[[UILabel alloc]initWithFrame:CGRectMake(0, 40, IPHONE_WIDTH, 1)];
        line1.backgroundColor=BACKCOLOR_GRAY;
        [searchView addSubview:line1];
    }else{
        titleArr=@[@"本月"];
    }
    
    for (int i=0; i<titleArr.count; i++) {
        UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(IPHONE_WIDTH/titleArr.count*i, self.empIds?40:0, IPHONE_WIDTH/titleArr.count, 40)];
        button.tag=100+i;
        [button setTitle:titleArr[i] forState:UIControlStateNormal];
        //设置图片
        if (self.empIds) {
            if (i==0){
                [button setImage:[UIImage imageNamed:@"k_ic_sx@2x"] forState:UIControlStateNormal];
            }else{
                [button setImage:[UIImage imageNamed:@"k_ic_xl@2x"] forState:UIControlStateNormal];
                [button setImage:[UIImage imageNamed:@"k_ic_sl@2x"] forState:UIControlStateSelected];
            }
        }else{
            [button setImage:[UIImage imageNamed:@"k_ic_xl@2x"] forState:UIControlStateNormal];
            [button setImage:[UIImage imageNamed:@"k_ic_sl@2x"] forState:UIControlStateSelected];
        }

        //谁知图片和文字的位置
        button.imageEdgeInsets=UIEdgeInsetsMake(10, button.width-30, 10, 10);
        button.titleEdgeInsets=UIEdgeInsetsMake(10, 10, 10, 30);
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        //[button setTitleColor:COLOR_SKYBLUE forState:UIControlStateSelected];
        //button.backgroundColor=[UIColor redColor];
        button.titleLabel.font=FONT_14;
        //        [button setTitleColor:COLOR_MIDBLUE forState:UIControlStateSelected];
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [searchView addSubview:button];
        
        if (i<titleArr.count-1) {
            UILabel *line=[[UILabel alloc]initWithFrame:CGRectMake(IPHONE_WIDTH/titleArr.count*(i+1), 50, 1, 20)];
            line.backgroundColor=BACKCOLOR_GRAY;
            [searchView addSubview:line];
        }
    }
    
    //分割线
    UILabel *line2=[[UILabel alloc]initWithFrame:CGRectMake(0, searchView.height-1, IPHONE_WIDTH, 1)];
    line2.backgroundColor=BACKCOLOR_GRAY;
    [searchView addSubview:line2];
}

#pragma mark - creatTableView
- (void)creatTableView{
    if (_tableBackView) {
        return;
    }
    CGFloat height=0;
    //计算tableView的高
    height=self.dateArr.count*44;
    if (height>IPHONE_HEIGHT-64-80) {
        height=IPHONE_HEIGHT-64-80;
    }
    _tableBackView=[[UIView alloc]initWithFrame:CGRectMake(0, self.empIds?80:40, IPHONE_WIDTH, IPHONE_HEIGHT-64-(self.empIds?80:40))];
    [self.view insertSubview:_tableBackView aboveSubview:self.view];
    _tableBackView.backgroundColor=[UIColor clearColor];
    //    [self.view addSubview:_tableBackView];
    
    UIView *alphaView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, _tableBackView.height)];
    alphaView.alpha=0.4;
    alphaView.backgroundColor=[UIColor blackColor];
    [_tableBackView addSubview:alphaView];
    
    //点击手势
    UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(TwoTapGestureRecognizer:)];
    tapGesture.delegate=self;
    [tapGesture setNumberOfTapsRequired:1];
    [tapGesture setNumberOfTouchesRequired:1];
    [alphaView addGestureRecognizer:tapGesture];
    
    _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH,height) style:UITableViewStylePlain];
    //_myTableView.backgroundColor=[UIColor redColor];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    _tableView.tag=110;
    _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    _tableView.showsVerticalScrollIndicator=NO;
    _tableView.showsHorizontalScrollIndicator=NO;
    //[self addTableViewUpdateRefresh:_tableView BindingIdentity:@""];
    //    [self addTableViewLoadMoreData:_tableView BindingIdentity:@""];
    [_tableBackView addSubview:_tableView];
    
    //    [UIView animateWithDuration:0.2 animations:^{
    //        _tableBackView.y=64+80;
    //    }];
    //    self.definesPresentationContext = YES;
}

#pragma mark - creatTableView
- (void)creatInfoTableView{
    if (_infoTableView) {
        return;
    }
    //列表数据初始化
    _dataArr=[NSMutableArray new];
    NSArray *section0=@[@"头像"];
    NSArray *section1=@[@"迟到",@"早退",@"旷工",@"未打卡"];
    NSArray *section2=@[@"事假",@"病假",@"其他假"];
    NSArray *section3=@[@"公出",@"加班"];
    [_dataArr addObject:section0];
    [_dataArr addObject:section1];
    [_dataArr addObject:section2];
    [_dataArr addObject:section3];
    
    _infoTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, self.empIds?80:40, IPHONE_WIDTH,IPHONE_HEIGHT-64-(self.empIds?80:40)) style:UITableViewStyleGrouped];
    //_myTableView.backgroundColor=[UIColor redColor];
    _infoTableView.delegate=self;
    _infoTableView.dataSource=self;
    _infoTableView.tag=111;
    _infoTableView.bounces=NO;
    _infoTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    _infoTableView.showsVerticalScrollIndicator=NO;
    _infoTableView.showsHorizontalScrollIndicator=NO;
    //[self addTableViewUpdateRefresh:_tableView BindingIdentity:@""];
    //    [self addTableViewLoadMoreData:_tableView BindingIdentity:@""];
    [self.view addSubview:_infoTableView];
    
    //    [UIView animateWithDuration:0.2 animations:^{
    //        _tableBackView.y=64+80;
    //    }];
    //    self.definesPresentationContext = YES;
}

#pragma mark- 搜索结果列表
- (void)creatSearchTableView{
    _searchBackView=[[UIView alloc]initWithFrame:CGRectMake(0, 40, IPHONE_WIDTH, IPHONE_HEIGHT-64-40)];
    _searchBackView.backgroundColor=[UIColor clearColor];
    [self.view addSubview:_searchBackView];
    
    UIView *alphaView=[[UIView alloc]initWithFrame:CGRectMake(0, 40, IPHONE_WIDTH, IPHONE_HEIGHT-64-40)];
    alphaView.alpha=0.4;
    alphaView.backgroundColor=[UIColor blackColor];
    [_searchBackView addSubview:alphaView];
    
    //点击手势
    UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(OneTapGestureRecognizer:)];
    tapGesture.delegate=self;
    [tapGesture setNumberOfTapsRequired:1];
    [tapGesture setNumberOfTouchesRequired:1];
    [alphaView addGestureRecognizer:tapGesture];
    
    CGFloat height=0;
    //计算tableView的高
    height=_searchListModel.dataArr.count*44;
    
    if (height>_searchBackView.height) {
        height=_searchBackView.height;
    }
    
    _searchTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, height) style:UITableViewStylePlain];
    _searchTableView.backgroundColor=[UIColor whiteColor];
    _searchTableView.delegate=self;
    _searchTableView.dataSource=self;
    _searchTableView.tag=112;
    _searchTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    //[self addTableViewUpdateRefresh:self.tableView BindingIdentity:@""];
    //    [self addTableViewLoadMoreData:_tableView BindingIdentity:@""];
    [_searchBackView addSubview:_searchTableView];
    
}

-(void)OneTapGestureRecognizer:(UIGestureRecognizer*)gr{
    
    if (_searchBackView) {
        [_searchBackView removeFromSuperview];
        _searchBackView=nil;
    }
    
}



-(void)TwoTapGestureRecognizer:(UIGestureRecognizer*)gr{
    
    if (_tableBackView) {
        //        [UIView animateWithDuration:0.2 animations:^{
        //            _tableBackView.y=64+80-(IPHONE_HEIGHT-64-80);
        //        } completion:^(BOOL finished) {
        [_tableBackView removeFromSuperview];
        _tableBackView=nil;
        //        }];
    }
    if (self.empIds) {
        UIButton *button=(UIButton *)[_searchTextField.superview viewWithTag:101];
        button.selected=NO;
    }else{
        UIButton *button=(UIButton *)[_searchTextField.superview viewWithTag:100];
        button.selected=NO;
    }
    
}

#pragma mark -签到历史
- (void)historyClick{
    SignInHistoryViewController *history=[SignInHistoryViewController new];
    history.empids=self.empIds;
    [self.navigationController pushViewController:history animated:YES];
}


#pragma mark -检索按钮点击

- (void)buttonClick:(UIButton *)selectButton{
    [self.view endEditing:YES];
    //如果是部门查询
    if (self.empIds) {
        if (selectButton.tag==100) {
            PersonSelectViewController *person=[PersonSelectViewController new];
            person.manageModel=self.manageModel;
            person.isPersonInfo=YES;
            __weak PersonInfoDetailViewController *mySelf=self;
            //根据筛选的回调函数判断是部门还是个人
            person.myBlock=^(NSString *depOrEmp,NSString *personStr,NSString *departStr){
                if ([depOrEmp isEqualToString:@"0"]) {//个人
                    mySelf.empIds=[personStr copy];
                    [mySelf getPersonalInformationInfoRequest];
                }
            };

            [self.navigationController pushViewController:person animated:YES];
        }else{
            selectButton.selected=!selectButton.selected;
            if (selectButton.selected) {
                //如果没有则创建  如果有则刷新
                if (!_tableBackView) {
                    [self creatTableView];
                }
            }else{
                [_tableBackView removeFromSuperview];
                _tableBackView=nil;
            }
        }
    }else{
        selectButton.selected=!selectButton.selected;
        if (selectButton.selected) {
            //如果没有则创建  如果有则刷新
            if (!_tableBackView) {
                [self creatTableView];
            }
        }else{
            [_tableBackView removeFromSuperview];
            _tableBackView=nil;
        }
    }

}

#pragma mark -搜索事件
- (void)searchClick{
    [self.view endEditing:YES];
    if (_searchTextField.text.length>0) {
        [self getDepartEmpNameRequestWithSearchtext:_searchTextField.text];
    }
}

#pragma mark -textFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    [self addTapGestureRecognizerWithView:self.view];
    return YES;
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
    [self removeTapGestureRecognizerWithView:self.view];
    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.view endEditing:YES];
    if (_searchTextField.text.length>0) {
        //[self getDutyFlowListRequestWithState:@"0"];
    }
    return YES;
}

#pragma mark - TableViewDelagate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (tableView.tag==111) {
        return _dataArr.count;
    }
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (tableView.tag==111) {
        NSArray *arr=_dataArr[section];
        return arr.count;
    }else if (tableView.tag==112){
        return _searchListModel.dataArr.count;
    }
    return self.dateArr.count;
    //return _newsListModel.dataArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView.tag==110) {
        //筛选条件
        NSString *cellID=@"StatisticsTableViewCell";
        StatisticsTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell=[[StatisticsTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
            //        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        }
        cell.messageLabel.text=self.dateArr[indexPath.row];

        return cell;
    }else if(tableView.tag==111){
        if (indexPath.section==0) {
            //个人信息
            NSString *cellID=@"PersonInfoHeadTableViewCell";
            PersonInfoHeadTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
            if (!cell) {
                cell=[[PersonInfoHeadTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
                cell.selectionStyle=UITableViewCellSelectionStyleNone;
                //cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            }
            [cell.headImageView setImageWithURL:[NSURL URLWithString:self.infoModel.imgUri] placeholderImage:[UIImage imageNamed:@"a_2@2x"]];
            cell.cqLabel.text=self.infoModel.attendanceEfficiency;
            cell.jxLabel.text=self.infoModel.checkGrade;
            cell.pmLabel.text=self.infoModel.performanceRanking;
            return cell;
        }else{
            //汇总信息
            NSString *cellID=@"PersonInfoTableViewCell";
            PersonInfoTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
            if (!cell) {
                cell=[[PersonInfoTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
                //        cell.selectionStyle=UITableViewCellSelectionStyleNone;
                cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            }
            //填充数据
            NSArray *titleArr=_dataArr[indexPath.section];
            cell.myTitleLabel.text=titleArr[indexPath.row];
            if (indexPath.section==1) {
                if (indexPath.row==0) {
                    cell.infoLabel.text=[self.infoModel.lateTimes stringByAppendingString:@"次"];;
                }else if (indexPath.row==1){
                    cell.infoLabel.text=[self.infoModel.leaveEarlyCount stringByAppendingString:@"次"];
                }else if (indexPath.row==2){
                    cell.infoLabel.text=[self.infoModel.absenteeismCount stringByAppendingString:@"次"];
                }else if (indexPath.row==3){
                    cell.infoLabel.text=[self.infoModel.noSignInCount stringByAppendingString:@"次"];
                }
            }else if (indexPath.section==2){
                if (indexPath.row==0) {
                    cell.infoLabel.text=[self.infoModel.thingVacation stringByAppendingString:@"天"];
                }else if (indexPath.row==1){
                    cell.infoLabel.text=[self.infoModel.diseaseVacation stringByAppendingString:@"天"];
                }else if (indexPath.row==2){
                    cell.infoLabel.text=[self.infoModel.elseVacation stringByAppendingString:@"天"];
                }
            }else if (indexPath.section==3){
                if (indexPath.row==0) {
                    cell.infoLabel.text=[self.infoModel.toleranCenumberOfDays stringByAppendingString:@"天"];
                }else if (indexPath.row==1){
                    cell.infoLabel.text=[self.infoModel.overtime stringByAppendingString:@"天"];
                }
            }
            return cell;
        }
    }else{
        //搜索结果列表
        NSString *cellID=@"CenterLabelTableViewCell";
        CenterLabelTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell=[[CenterLabelTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
            cell.selectionStyle=UITableViewCellSelectionStyleDefault;
            UILabel *line=[[UILabel alloc]initWithFrame:CGRectMake(0, 43, IPHONE_WIDTH, 1)];
            line.backgroundColor=BACKCOLOR_GRAY;
            [cell.contentView addSubview:line];
        }
        AddressSearchModel *searchModel=_searchListModel.dataArr[indexPath.row];
        cell.myTitle.text=[NSString stringWithFormat:@"%@(%@)",searchModel.respName,[searchModel.isDepart isEqualToString:@"0"]?@"个人":@"部门"];
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    //计算内容的宽和高
    //    if (_selectButton==2) {
    //        return 44;
    //    }
    if (tableView.tag==111) {
        if (indexPath.section==0) {
            return 100;
        }else{
            return 44;
        }
    }
    return 44;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (tableView.tag==110) {
        return 0;
    }
    if (section==0) {
        return 10;
    }
    return 30;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section!=0) {
        UIView *footView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, 30)];
        footView.backgroundColor=[UIColor clearColor];
        //图标
        UIImageView *imageView=[MyControl creatImageViewWithFrame:CGRectMake(8, 8, 15, 15) imageName:@"k_ic_yctj@2x"];
        [footView addSubview:imageView];
        
        UILabel *title=[MyControl creatLabelWithFrame:CGRectMake(imageView.x+imageView.width+8, imageView.y, 100, imageView.height) text:@""];
        title.font=FONT_14;
        [footView addSubview:title];
        
        if (section==1) {
            UIButton *signin=[MyControl creatButtonWithFrame:CGRectMake(IPHONE_WIDTH-80, 0, 70, 30) target:self sel:@selector(historyClick) tag:310 image:nil title:@"签到历史"];
            signin.titleLabel.font=[UIFont systemFontOfSize:14];
            [footView addSubview:signin];
        }
        if (section==1) {
            title.text=@"签到异常统计";
        }else if (section==2){
            title.text=@"请假统计";
        }else{
            title.text=@"其他";
        }
        return footView;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 1;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView.tag==110) {
        if ([_dateArr[indexPath.row] isEqualToString:@"本月"]) {
            self.beginStr=[LZXHelper getFirstDayInMonth];
            self.endStr=[LZXHelper getLastDayInMonth];
        }else if ([_dateArr[indexPath.row] isEqualToString:@"上月"]) {
            self.beginStr=[LZXHelper getFirstDayInLastMonth];
            self.endStr=[LZXHelper getLastDayInLastMonth];
        }else if ([_dateArr[indexPath.row] isEqualToString:@"本季度"]) {
            self.beginStr=[LZXHelper getFirstDayWithQuarter];
            self.endStr=[LZXHelper getLastDayWithQuarter];
        }else if ([_dateArr[indexPath.row] isEqualToString:@"上季度"]) {
            self.beginStr=[LZXHelper getFirstDayWithLastQuarter];
            self.endStr=[LZXHelper getLastDayWithLastQuarter];
        }else if ([_dateArr[indexPath.row] isEqualToString:@"上半年"]) {
            self.beginStr=[LZXHelper getFirstDayWithFirstHalfAYear];
            self.endStr=[LZXHelper getLastDayWithFirstHalfAYear];
        }else if ([_dateArr[indexPath.row] isEqualToString:@"下半年"]) {
            self.beginStr=[LZXHelper getFirstDayWithSecondHalfAYear];
            self.endStr=[LZXHelper getLastDayWithSecondHalfAYear];
        }
        [self getPersonalInformationInfoRequest];
        //将选择的显示到button上
        UIButton *button=nil;
        if (self.empIds) {
            button=(UIButton *)[_searchTextField.superview viewWithTag:101];
            button.selected=NO;
        }else{
            UIView *searchView=[self.view viewWithTag:199];
            button=(UIButton *)[searchView viewWithTag:100];
            button.selected=NO;
        }
        
        [button setTitle:_dateArr[indexPath.row] forState:UIControlStateNormal];
        [_tableBackView removeFromSuperview];
        _tableBackView=nil;
    }else if (tableView.tag==111){
        if (indexPath.section==0) {
            return;
        }
        NSArray *titleArr=_dataArr[indexPath.section];
        //进入考勤 请假历史情况查看
        PersonDetailInfoViewController *info=[PersonDetailInfoViewController new];
        info.itemStr=titleArr[indexPath.row];
        info.empName=self.infoModel.name;
        info.beginStr=self.beginStr;
        info.endStr=self.endStr;
        info.empIds=self.empIds?self.empIds:[LZXHelper getSessionID];
        info.itemCode=self.infoModel.empCode;
        NSString *businessCode=@"";
        if ([titleArr[indexPath.row] isEqualToString:@"事假"]) {
            businessCode=@"SJ0002";
        }else if ([titleArr[indexPath.row] isEqualToString:@"病假"]){
            businessCode=@"BJ0001";
        }else if ([titleArr[indexPath.row] isEqualToString:@"公出"]){
            businessCode=@"GC0009";
        }else if ([titleArr[indexPath.row] isEqualToString:@"加班"]){
            businessCode=@"JB0011";
        }else if ([titleArr[indexPath.row] isEqualToString:@"其他假"]){
            businessCode=@"QT";
        }
        info.businessCode=businessCode;
        [self.navigationController pushViewController:info animated:YES];
    }else{
        AddressSearchModel *searchModel=_searchListModel.dataArr[indexPath.row];
        //如果是部门
        if ([searchModel.isDepart isEqualToString:@"1"]) {
            StatisticsListViewController *listView=[StatisticsListViewController new];
            listView.navaTitle=searchModel.respName;
            //listView.memberNames=self.memberNames;
            [self.navigationController pushViewController:listView animated:YES];
        }else{
            //如果是个人
            PersonInfoDetailViewController *person=[PersonInfoDetailViewController new];
            person.empIds=searchModel.respId;

            [self.navigationController pushViewController:person animated:YES];
        }
        //搜索的时候移除掉searchBackView
        if (_searchBackView) {
            [_searchBackView removeFromSuperview];
            _searchBackView=nil;
        }
    }
}

#pragma mark -个人信息汇总查询
- (void)getPersonalInformationInfoRequest{
    NSDictionary *dict=@{
                         @"beginTime":self.beginStr?self.beginStr:@"",
                         @"endTime":self.endStr?self.endStr:@"",
                         @"empId":self.empIds?self.empIds:[LZXHelper getSessionID],
                         };
    
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    // __weak AddressBookViewController *mySelf=self;
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:[[UIApplication sharedApplication].delegate window]];
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getPersonalInformationInfo soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:[[UIApplication sharedApplication].delegate window]];
        
        //解析数据
        self.infoModel=[[PersonInfoDetailModel alloc]initWithResponse:responseObject];
        if ([self.infoModel.code isEqualToString:@"200"]) {
            [self setNavigationTitle:[NSString stringWithFormat:@"%@汇总查询",self.infoModel.name]];
            //            //如果有先移除
            //            if (!self.backScrollView) {
            //                //页面汇总信息按钮
            //                [self creatFunctionButtonView];
            //            }else{
            //                [self refreshInfoButton];
            //            }
            //
            [_infoTableView reloadData];
        }else if([self.infoModel.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:self.infoModel.msg View:[[UIApplication sharedApplication].delegate window]];
        }
    } failure:^(NSError *error) {
        [LZXHelper hideLoadViewWithView:[[UIApplication sharedApplication].delegate window]];
    }];
}

#pragma mark -模糊查询条件
- (void)getDepartEmpNameRequestWithSearchtext:(NSString *)searchText{
    NSDictionary *dict=@{
                         @"inputValue":searchText,
                         @"isDepartOrEmp":@"2",
                         };
    
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    // __weak AddressBookViewController *mySelf=self;
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:[[UIApplication sharedApplication].delegate window]];
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getDepartEmpName soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:[[UIApplication sharedApplication].delegate window]];
        
        //解析数据
        _searchListModel=[[AddressSearchModel alloc]initWithResponse:responseObject];
        if ([_searchListModel.code isEqualToString:@"200"]) {
            if (!_searchBackView) {
                [self creatSearchTableView];
            }else{
                CGFloat height=0;
                //计算tableView的高
                height=_searchListModel.dataArr.count*44;
                
                if (height>_searchBackView.height) {
                    height=_searchBackView.height;
                }
                _searchTableView.height=height;
                [_searchTableView reloadData];
            }
            if (_searchListModel.dataArr.count==0) {
                //增加提示语
                [self addReminderViewWithFrame:_searchTableView.frame msg:@"没有搜索到该员工！" backView:_searchTableView];
            }else{
                //移除提示语
                [self removeReminderView];
            }
        }else if([_searchListModel.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:_searchListModel.msg View:self.view];
        }
    } failure:^(NSError *error) {
        [LZXHelper hideLoadViewWithView:[[UIApplication sharedApplication].delegate window]];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
